/*
@Project:SpringBoot
@Date:2023/2/28
@Create:Ya Potato
@IDE:IntelliJ IDEA 2023.1
@version:JDK 1.8
*/

package restservice;

import java.util.concurrent.atomic.AtomicLong;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;


@RunWith(SpringRunner.class)
@SpringBootTest(classes= Greeting.class)
public class GreetingController {
    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @GetMapping("/greeting")
    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
        return new Greeting(counter.incrementAndGet(), String.format(template, name));
    }
}
